package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.CommoditiesListBiz;
import cn.hrlly.tao2shou.biz.CommoditiesListBizImpl;
import cn.hrlly.tao2shou.domain.CommodityList;
import cn.hrlly.tao2shou.listener.OnCommoditiesListListener;
import cn.hrlly.tao2shou.view.view_interface.CommoditiesListView;

/**
 * User: gengliang
 * Date: 2016-01-28
 * Time: 18:55
 */

public class CommoditiesListPresenterImpl implements OnCommoditiesListListener,CommoditiesListPresenter {

    private CommoditiesListBiz commoditiesListBiz;
    private CommoditiesListView commoditiesListView;

    public CommoditiesListPresenterImpl(CommoditiesListView commoditiesListView,Context context){
        this.commoditiesListBiz=new CommoditiesListBizImpl(this,context);
        this.commoditiesListView=commoditiesListView;
    }

    //联网显示商品列表
    @Override
    public void showCommoditiesList() {
        CommodityList commodityList=new CommodityList();
        commodityList.setPage(commoditiesListView.getPage());
        commodityList.setPageCount(commoditiesListView.getPageCount());
        commodityList.setSortAccording(commoditiesListView.getSortAccording());
        commodityList.setLongitude(commoditiesListView.getLongitude());
        commodityList.setLantitude(commoditiesListView.getLantitude());
        commoditiesListBiz.showCommoditiesList(commodityList);
    }

    //缓存显示商品列表
    @Override
    public void showCacheCommoditiesList() {
        CommodityList commodityList=commoditiesListBiz.getCacheCommoditiesList();
        if(commodityList!=null)
            commoditiesListView.showListView(commodityList);
    }

    @Override
    public void showCommoditiesListSucc(CommodityList commodityList) {
        commoditiesListView.showListView(commodityList);

        //将商品列表缓存
        commoditiesListBiz.saveCacheCommoditiesList(commodityList);
    }

    @Override
    public void showCommoditiesListFail(String errorMessage) {
        commoditiesListView.showMessage(errorMessage);
    }

    @Override
    public void showCommoditiesListFail(int errorMessage) {
        commoditiesListView.showMessage(errorMessage);
    }
}
